{*
  Object Pascal simple application security manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit SecurityRoutines;

interface

uses
  Classes,
  Dialogs,
  Forms,
  Messages,
  SecHash,
  SysUtils,
  Registry,
  Windows;

function EncodeString( strnString: AnsiString; intgPrecision: Word ): AnsiString;
function LoadProductEvaluation( strnProductName: AnsiString ): Integer;
function SaveProductEvaluation( strnProductName: AnsiString ): Integer;
function LoadProductRegistered( strnProductName: AnsiString ): Boolean;
function SaveProductRegistered( strnProductName: AnsiString ): Boolean;
function LoadProductSerialNumber( strnProductName, strnUserFullName, strnOrganisation: AnsiString ): AnsiString;
function SaveProductSerialNumber( strnProductName, strnUserFullName, strnOrganisation: AnsiString ): AnsiString;

implementation

function EncodeString( strnString: AnsiString; intgPrecision: Word ): AnsiString;
var
  schsSecurityHash: TSecHash;
  intdIntegerDigest: TIntDigest;
begin

  if intgPrecision = 0 then intgPrecision := 255;

  schsSecurityHash := TSecHash.Create( Application );

  try
    intdIntegerDigest := schsSecurityHash.ComputeString( strnString );
    Result := Copy(
                   IntToHex( intdIntegerDigest[0], 8 ) +
                   IntToHex( intdIntegerDigest[1], 8 ) +
                   IntToHex( intdIntegerDigest[2], 8 ) +
                   IntToHex( intdIntegerDigest[3], 8 ) +
                   IntToHex( intdIntegerDigest[4], 8 ),
                   1, intgPrecision );

  finally
    schsSecurityHash.Free;
  end;//try

end;

//_____________________________________________________________________________

function LoadProductEvaluation( strnProductName: AnsiString ): Integer;
var
  Registry: TRegistry;
begin

  Registry := TRegistry.Create;
  try
    Registry.RootKey := HKEY_CURRENT_USER;
  finally
    Registry.Free;
  end;//try

end;

//_____________________________________________________________________________

function SaveProductEvaluation( strnProductName: AnsiString ): Integer;
begin
end;

//_____________________________________________________________________________

function LoadProductRegistered( strnProductName: AnsiString ): Boolean;
begin
end;

//_____________________________________________________________________________

function SaveProductRegistered( strnProductName: AnsiString ): Boolean;
begin
end;

//_____________________________________________________________________________

function LoadProductSerialNumber( strnProductName, strnUserFullName, strnOrganisation: AnsiString ): AnsiString;
begin
  Result := EncodeString( strnProductName + '/' + strnUserFullName + '/' + strnOrganisation, 16 );
end;

//_____________________________________________________________________________

function SaveProductSerialNumber( strnProductName, strnUserFullName, strnOrganisation: AnsiString ): AnsiString;
begin
end;

end.
